package ai.mspbots.service.task.controller;

import ai.mspbots.service.task.entity.TaskEntity;
import ai.mspbots.service.task.message.SendTask;
import cn.hutool.json.JSONUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/task")
public class TaskController {

    private static final Logger logger = LoggerFactory.getLogger(TaskController.class);

    @Autowired
    private SendTask sendTask;

    @GetMapping("/{id}")
    @ResponseBody
    public TaskEntity getReport(@PathVariable("id")Long id, HttpServletRequest request) {
        String header = request.getHeader("trace.id");
        logger.info("id={}", id);
        TaskEntity taskEntity = TaskEntity.of(id);
        sendTask.sendRabbitMQ(JSONUtil.toJsonStr(taskEntity));
        return taskEntity;
    }
}
